from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import TouchActions,ActionChains
from user import *

chrome_option = Options()
driver = webdriver.Chrome(chrome_options=chrome_option)
driver.get("https://www.ximalaya.com/renwen/11438153/")
wait = WebDriverWait(driver,10)
driver.maximize_window()
#586
def get_sound_list(driver):
    actions = TouchActions(driver)
    actions.scroll(0,800)
    actions.perform()

    slist = driver.find_elements_by_xpath("//div[@class='sound-list _OO']/ul/li/div/a")
    for sound in slist:
        page = sound.get_attribute('href')
        js = 'window.open("%s");'%page
        driver.execute_script(js)
        driver.switch_to_window(driver.window_handles[1])
        wait.until(EC.presence_of_element_located((By.CLASS_NAME,'cover')))
        play_btn = driver.find_element_by_css_selector('.play-btn')
        play_btn.click()





wait.until(EC.presence_of_element_located((By.CLASS_NAME,'user-notice')))
login(driver)
wait.until(EC.presence_of_element_located((By.CLASS_NAME,'new-notices')))
get_sound_list(driver)
driver.close()